﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;


public partial class UControls_WUC_DialogTextBox : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (tb_width != 0) { txt_data.Width = tb_width; }
            cv_num.EnableClientScript = validateNumber;

            txt_data.Text = Text;
            string clientid_txt_data = txt_data.ClientID;   //获取客户端文本框ID
            StringBuilder sb = new StringBuilder();
            sb.Append("var result = open_Dialog('").Append(dialogURL).Append("',").Append(dialogWidth)
                .Append(",").Append(dialogHeight).Append(",").Append(clientid_txt_data).Append(".value);")
                .Append("if(result != ''){").Append(clientid_txt_data).Append(".value = result;}");
            btn_script = sb.ToString();
            DataBind();
        }
    }

    #region 成员
    string dialogURL = string.Empty;
    int dialogWidth = 0;
    int dialogHeight = 0;
    int tb_width = 0;
    protected string btn_script = string.Empty; //按钮脚本  
    protected string btn_title = string.Empty;  //功能提示
    bool validateNumber = true; //是否验证数字
    #endregion

    #region 属性
    /// <summary>
    /// 是否验证数字
    /// </summary>
    public bool ValidateNumber
    {
        set { validateNumber = value; }
        get { return validateNumber; }
    }
    /// <summary>
    /// 设置对话页面地址
    /// </summary>    
    public string DialogURL
    {
        set { dialogURL = value; }
        get { return dialogURL; }
    }

    /// <summary>
    /// 设置功能提示
    /// </summary>
    public string DialogTitle
    {
        set { btn_title = value; }
    }
   
    /// <summary>
    /// 设置对话页面宽度
    /// </summary>
    public int DialogWidth
    {
        set { dialogWidth = value; }
    }
    
    /// <summary>
    /// 设置对话页面高度
    /// </summary>
    public int DialogHeight
    {
        set { dialogHeight = value; }
    }
    
    /// <summary>
    /// 设置或获取数据文本框的值
    /// </summary>
    public string Text
    {
        set { txt_data.Text = value; }
        get { return txt_data.Text.Trim(); }
    }

    /// <summary>
    /// 设置文本框的宽度
    /// </summary>
    public int TB_Width
    {
        set { tb_width = value; }
    }
    /// <summary>
    /// 获取文本框的客户端名称
    /// </summary>
    public string TB_ClientID
    {
        get { return txt_data.ClientID; }
    }
    #endregion
}
